﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using LowLevelGraphics.Types;
using LowLevelGraphics.Types.Interval;

namespace ImageRecognition2.Forms
{
    /// <summary>
    /// 
    /// </summary>
    public partial class FormColorSelection : Form
    {
        public FormColorSelection()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Gets the A.
        /// </summary>
        /// <value>The A.</value>
        public int A
        {
            get { return Convert.ToInt32(numericUpDownA1.Value); }
        }

        /// <summary>
        /// Gets or sets the R.
        /// </summary>
        /// <value>The R.</value>
        public int R
        {
            get { return Convert.ToInt32(numericUpDownR1.Value); }
            set { numericUpDownR1.Value = value; }
        }

        /// <summary>
        /// Gets or sets the G
        /// </summary>
        public int G
        {
            get { return Convert.ToInt32(numericUpDownG1.Value); }
            set { numericUpDownG1.Value = value; }
        }

        /// <summary>
        /// Gets or sets the B.
        /// </summary>
        /// <value>The B.</value>
        public int B
        {
            get { return Convert.ToInt32(numericUpDownB1.Value); }
            set { numericUpDownB1.Value = value; }
        }

        /// <summary>
        /// Gets or sets the color1.
        /// </summary>
        /// <value>The color1.</value>
        public Color Color1
        {
            get { return boxColor1.BackColor; }
            set { boxColor1.BackColor = value; }
        }

        /// <summary>
        /// Gets or sets the color2.
        /// </summary>
        /// <value>The color2.</value>
        public Color Color2
        {
            get { return boxColor2.BackColor; }
            set { boxColor2.BackColor = value; }
        }

        /// <summary>
        /// Gets or sets a value indicating whether this instance is range.
        /// </summary>
        /// <value><c>true</c> if this instance is range; otherwise, <c>false</c>.</value>
        public bool IsRange
        {
            get { return radioButtonRange.Checked; }
            set { radioButtonRange.Checked = value; }
        }

        /// <summary>
        /// Gets or sets a value indicating whether this instance is tolerance.
        /// </summary>
        /// <value>
        /// 	<c>true</c> if this instance is tolerance; otherwise, <c>false</c>.
        /// </value>
        public bool IsTolerance
        {
            get { return radioButtonTolerance.Checked; }
            set { radioButtonTolerance.Checked = value; }
        }

        /// <summary>
        /// Gets the color ranges.
        /// </summary>
        /// <value>The color ranges.</value>
        public Color[] ColorRanges
        {
            get { return new Color[] { boxColor1.BackColor, boxColor2.BackColor }; }
        }

        /// <summary>
        /// Gets color range
        /// </summary>
        public ColorRange ColorRange
        {
            get { return new ColorRange(boxColor1.BackColor, boxColor2.BackColor); }
        }

        private void cbChooseColor1_Click(object sender, EventArgs e)
        {
            ChooseColor(boxColor1);

            numericUpDownA1.Value = boxColor1.BackColor.A;
            numericUpDownR1.Value = boxColor1.BackColor.R;
            numericUpDownG1.Value = boxColor1.BackColor.G;
            numericUpDownB1.Value = boxColor1.BackColor.B;
        }

        /// <summary>
        /// Handles the Click event of the cbChooseColor2 control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void cbChooseColor2_Click(object sender, EventArgs e)
        {
            ChooseColor(boxColor2);

            numericUpDownA2.Value = boxColor2.BackColor.A;
            numericUpDownR2.Value = boxColor2.BackColor.R;
            numericUpDownG2.Value = boxColor2.BackColor.G;
            numericUpDownB2.Value = boxColor2.BackColor.B;
        }

        /// <summary>
        /// Chooses the color.
        /// </summary>
        /// <param name="_lb">The _LB.</param>
        private void ChooseColor(Label _lb)
        {
            ColorDialog colorDialog = new ColorDialog();
            if (colorDialog.ShowDialog() == DialogResult.OK)
            {
                _lb.BackColor = colorDialog.Color;
            }
        }

        /// <summary>
        /// Handles the Click event of the cbOK control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void cbOK_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void FormColorSelection_Load(object sender, EventArgs e)
        {
        }

        /// <summary>
        /// Handles the Click event of the cbCancel control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void cbCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
    }
}
